package com.fccommunity.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.fccommunity.R;
import com.fccommunity.adapter.MessageAdapter;
import com.fccommunity.adapter.base.RecycleViewItemListener;
import com.fccommunity.base.BaseActivity;
import com.fccommunity.widget.DivItemDecoration;
import com.malinskiy.superrecyclerview.SuperRecyclerView;

/**
 * Created by yiwei on 16/5/3.
 */
public class MessageActivity extends BaseActivity{

    private SuperRecyclerView recyclerView;
    private MessageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);

        initView();
    }

    private void initView() {
        recyclerView = (SuperRecyclerView) findViewById(R.id.recycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                // Do your refresh
            }
        });
        adapter = new MessageAdapter();
        adapter.setItemListener(new RecycleViewItemListener() {
            @Override
            public void onItemClick(int position) {
                String url = "http://www.baidu.com";
                startActivity(WebViewActivity.newIntent(context,"", url));
            }

            @Override
            public boolean onItemLongClick(int position) {
                return false;
            }
        });
        recyclerView.setAdapter(adapter);
        recyclerView.addItemDecoration(new DivItemDecoration(20));

    }

    @Override
    protected void initTitle() {
        titleBar.setTitle("通知公告");
        titleBar.setLeftImageResource(R.mipmap.back);
        titleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public static Intent newIntent(Context context) {

        return new Intent(context, MessageActivity.class);
    }
}
